<template>
  <div>
    <el-button
    :type="btncontent.type"
    :icon="btncontent.icon"
    :loading="btncontent.loading"
    @click.native="submitfunc"
    :size="btncontent.size"
    :style="btncontent.style"
    >
    <slot name="left"></slot>
    {{btncontent.text}}
    <slot name="right"></slot>
    </el-button>
  </div>
</template>

<script>
export default {
  props: {
    content: Object
  },
  data () {
    return {
      btncontent: {}
    }
  },
  created () {
    this.btncontent = Object.assign({}, this.btncontent, {
      type: 'primary',
      icon: '',
      loading: false,
      round: false,
      circle: false,
      size: 'medium',
      url: '',
      typeurl: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json, text/javascript, */*; q=0.01'
      },
      jsontype: false,
      data: {}
    }, this.content)
  },
  methods: {
    submitfunc () {
      console.log(111)
      this.btncontent.loading = true
      console.log(this.btncontent)
      if (!this.btncontent.jsontype) {
        this.$ajax({
          url: this.btncontent.url,
          type: this.btncontent.typeurl,
          headers: this.btncontent.headers,
          data: {
            ...this.btncontent.data
          }
        }).then(data => {
          this.btncontent.loading = false
          this.$emit('btnajaxfunc', data)
        })
      } else {
        this.$ajax({
          url: this.btncontent.url,
          type: this.btncontent.typeurl,
          headers: this.btncontent.headers,
          data: JSON.stringify(Object.assign({}, this.btncontent.data))
        })
      }
    }
  }
}
</script>


